﻿Type.registerNamespace('MS.InformationManagement.SearchRefinementPanel');

MS.InformationManagement.SearchRefinementPanel.Initialize = function (searchrefinementpanel) {
    var currentselectedtab = null;
    var currentactivetrigger = null;
    $('#' + searchrefinementpanel + ' h3 a').each(function (index) {
        var currenttabtrigger = $(this);
        var targettab = $(currenttabtrigger.attr('href'));

        currenttabtrigger.click(function () {

            MS.InformationManagement.Common.SetCookie('refinementsearchtab', currenttabtrigger.attr('href'), 1);

            if (currentactivetrigger != null) {
                currentactivetrigger.removeClass('bottom-borderless');
            }

            currentactivetrigger = $(this).parent();
            currentactivetrigger.addClass('bottom-borderless');
            targettab.show();

            if (currentselectedtab != null && currentselectedtab != targettab) {
                currentselectedtab.hide();
            }
            currentselectedtab = targettab;
        });
    });

    var cookiePersistedValue = MS.InformationManagement.Common.GetCookie('refinementsearchtab');
    if (cookiePersistedValue != '') { $('a[href="' + cookiePersistedValue + '"]').click(); }
}